<template>
	<view class="lock flex flexC flexCol flexJC page">
		<image class="r4 logo mb15" src="/static/logo.jpg" mode="aspectFill"></image>
		<view class="fs18 c00">雀侠自助棋牌台球</view>
		<view class="btn flex flexC r40 py15 px22 cff">
			<view class="flex1" @click="$refs.keyboardPackage.open()">
				<view class="fs18">扫码开门</view>
				<view>顾客自助扫码开门</view>
			</view>
			<image class="arrow" src="/static/img/icon/arrow-round.png" mode="aspectFill"></image>
		</view>
		
		<view class="btn2 flex flexC r40 py15 px22 cff">
			<view class="flex1" @click="clickBook">
				<view class="fs18">未预定</view>
				<view>立即预定</view>
			</view>
			<image class="arrow" src="/static/img/icon/arrow-round.png" mode="aspectFill"></image>
		</view>
		
		
		<keyboard-package ref="keyboardPackage" @onConfirm="onConfirm">
			<template v-slot:head>
				<view class="bgff px16 pt4 pb12">
					<view class="c00 fs14 bold6 flex flexC flexB">
						<text>开锁码</text>
						<text @click="onClose" class="fs26 px10">×</text>
					</view>
					<view class="c99 fs14 bold6 cff0">
						开锁码为预订人手机号后4位
					</view>
				</view>

			</template>
			<template v-slot:foot>
				<view class="bgff px16 py12">
					<view class="tipsbox flex flexC px20 py18 r3">
						<image class="tipImg" src="/static/img/icon/tips.png" mode="aspectFill"></image>
						<view class="flex1 pl16 c99">
							<view class="fs13 flex flexC flexB">
								<text>开锁失效/异常时</text>
							</view>
							<view class="fs12 mt3" @click="call">
								{{name}}商家电话：{{tel}}
							</view>
						</view>
					</view>

				</view>
			</template>
		</keyboard-package>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shop_id: '',
				tel: '',
				name:''
			};
		},

		onLoad(option) {

			
			if (option.scene) {
			
				this.shop_id = option.scene;

			}
			this.getInfo();
		},

		onShow() {
			this.$refs.keyboardPackage.open()
		},
		methods: {
			
			clickBook(){
				uni.navigateTo({
					url:'../shop/detail?id='+this.shop_id
				})
			},
			
			call(){
				uni.makePhoneCall({
					phoneNumber:this.tel
				})
			},
			
			getInfo(){
				let that = this;
				let param = {
					shop_id:this.shop_id
				}
				this.$api.getShopDetailInfo(param).then(res => {
				
					if (res.code == 1) {
						that.tel = res.data.tel;
						that.name = res.data.name;
					}
					console.info(res);
				})
				
			},
			
			onClose() {
				this.$refs.keyboardPackage.close()
			},
			onConfirm(val) {
				
				let that = this;
				let param = {
					shop_id:this.shop_id,
					code:val.join('')
				}
				this.$api.openDaDoor(param).then(res => {
				
					if (res.code == 1) {
						uni.showToast({
							title:"开门成功",
							icon:'none'
						})
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
					console.info(res);
				})
				
				console.log(val.join(''))
			}
		}
	}
</script>

<style lang="scss" scoped>
	.lock {
		height: 100vh;
		background-color: #FDE7F3;

		.tipsbox {
			background-color: #FDF1E5;

			.tipImg {
				width: 68rpx;
				height: 68rpx;
			}
		}

		.logo {
			width: 128rpx;
			height: 128rpx;
		}

		.btn {
			width: calc(100% - 148rpx);
			box-sizing: border-box;
			background: linear-gradient(to bottom, #F8B62B, #F8B62B);
			margin-top: 100rpx;
			.arrow {
				width: 68rpx;
				height: 68rpx;
			}
		}
		
		.btn2 {
			width: calc(100% - 148rpx);
			box-sizing: border-box;
			margin-top: 30rpx;
			
			background: linear-gradient(to bottom, #F8B62B, #F8B62B);
			.arrow {
				width: 68rpx;
				height: 68rpx;
			}
		}
	}
</style>